//
//  ByScanCodeVC.m
//  mijifen_ios
//
//  Created by mc on 2017/10/23.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByScanCodeVC.h"

// vc
#import "ByScanCodeSuccessVC.h"

@interface ByScanCodeVC ()<UITextFieldDelegate>

@end

@implementation ByScanCodeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"扫码收款";
    self.view.backgroundColor = BY_TABLE_COLOR;
    [self addLeftBackBarButtonItem];
    [self createViews];
}
#pragma mark - 创建视图
- (void)createViews{
    UIImageView *img = [[UIImageView alloc] init];
    [self.view addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(40);
        }else{
            make.top.equalTo(self.view.mas_top).offset(40);
        }
        make.left.equalTo(self.view.mas_left).offset((SCREEN_WIDTH - 60) / 2);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    img.image = [UIImage imageNamed:@"Index_scanCode"];
    
    UILabel *priceLabel = [[UILabel alloc] init];
    [self.view addSubview:priceLabel];
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(img.mas_bottom).offset(40);
        make.left.equalTo(self.view.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 30));
    }];
    priceLabel.text = @"请输入用户的消费金额";
    priceLabel.font = FONT(18);
    priceLabel.textAlignment = NSTextAlignmentCenter;
    
    UIView *priceView = [[UIView alloc] init];
    [self.view addSubview:priceView];
    [priceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(20);
        make.top.equalTo(priceLabel.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40, 55));
    }];
    priceView.backgroundColor = [UIColor whiteColor];
    priceView.layer.cornerRadius = 4.0;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [priceView addSubview:titleLabel];
    CGFloat width = [@"金额" getSizeOfString:18].width + 5;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(priceView.mas_top).offset(10);
        make.left.equalTo(priceView.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(width, 35));
    }];
    titleLabel.text = @"金额";
    
    UITextField *priceTf = [[UITextField alloc] init];
    [priceView addSubview:priceTf];
    [priceTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(priceView.mas_right).offset(-15);
        make.top.equalTo(priceView.mas_top).offset(10);
        make.left.equalTo(titleLabel.mas_right);
        make.bottom.equalTo(priceView.mas_bottom).offset(-10);
    }];
    priceTf.placeholder = @"0.0";
    priceTf.font = FONT(18);
    priceTf.textAlignment = NSTextAlignmentRight;
    priceTf.keyboardType = UIKeyboardTypeDecimalPad;
    priceTf.delegate = self;
    
    UIButton *sureButton = [[UIButton alloc] init];
    [self.view addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
        make.left.equalTo(self.view.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));
        
    }];
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [sureButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [sureButton setBackgroundColor:BY_THEME_COLOR];
    [sureButton addTarget:self action:@selector(sureAction) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark -
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField.text.length == 5) {
        return NO;
    }
    return YES;
}

- (void)sureAction{
    ByScanCodeSuccessVC *vc = [[ByScanCodeSuccessVC alloc] init];
    [self by_normalPush:vc hasNavi:YES];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
